<?php

namespace app\admin\controller;
class Massage extends base
{


    public function index()
    {
        $this->datas['pid'] = 0;
        $list = $this->model->where($this->datas)->paginate();
        $this->assign('num', $this->model->count());
        $this->assign('list', $list);
        return $this->fetch();
    }


    public function edit($id)
    {
        //修改状态
        $this->model->where('id',$id)->update(['status'=>'1']);
        return parent::edit($id); // TODO: Change the autogenerated stub
    }

    /**
     * 保存
     */
    public function save()
    {
        if (!$this->request->isPost()) {
            $this->error('请求失败');
        }
        $data = $this->request->post();
//        $result = $this->validate($data, 'Massage');
//        if (true !== $result) {
//            $this->error($result);
//        }
//        if(!empty($data['id'])){
//           return $this->update($data);
//        }

        $res = $this->model->allowField(['pid', 'center', 'name'])->save($data);
        if ($res) {
            $this->success('保存成功');
        } else {
            $this->error('添加失败');
        }
    }
}
